﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Battery : MonoBehaviour
{
    private EventSystem eventSystem;
    [SerializeField]
    private Sprite[] sprites;
    private SpriteRenderer m_spriteRenderer;
    private Character player;

    [SerializeField]
    private bool _Active = true;
    public bool Active
    {
        get => _Active;
        set
        {
            if (Active == value)
                return;
            m_spriteRenderer.enabled = value;
            _Active = value;
        }
    }

    private void Start()
    {
        player = Character.Instance;
        eventSystem = Service.Get<EventSystem>();
        m_spriteRenderer = GetComponent<SpriteRenderer>();
        eventSystem.EnergyChange += OnEnergyChange;
    }

    private void OnEnergyChange(int val)
    {
        m_spriteRenderer.sprite = sprites[val];
    }

    private void FixedUpdate()
    {
        Active = !player.b_died && !player.Grounded;
    }
}
